package cm.iccsoft.android.telecomcost;

import com.google.gson.Gson;

import android.app.Application;

public class TelecomCost extends Application {
	//keep references to our global resources
    private static DatabaseManager db = null;
    private static Gson gson = null;
    private static TelecomCost instance = null;

    /**
     * Convenient accessor, saves having to call and cast getApplicationContext() 
     */
    public static TelecomCost getInstance() {
        checkInstance();
        return instance;
    }

    /**
     * Accessor for some resource that depends on a context
     */
    public static DatabaseManager getDatabaseManager() {
        if (db == null) {
            checkInstance();
            db = new DatabaseManager(instance, null, null, 0);
        }
        return db;
    }

    /**
     * Accessor for another resource that depends on a context
     */
    public static Gson getGson() {
        if (gson == null) {
            checkInstance();
            gson = new Gson();
        }
        return gson;
    }

    private static void checkInstance() {
        if (instance == null)
            throw new IllegalStateException("Application not created yet!");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //provide an instance for our static accessors
        instance = this;
    }

}
